﻿
function CreatePage(curPage) {
    var messageType = $("#messageType").val();
    var searchValue = $("#SearchValue").val();
    var retVal = "";
    switch (messageType) {
        case "HotVideo":
            retVal = aboutlinkvideo.GetHotVedioListByDay(curPage, $("#hidUserID").val()).value;
            break;
        case "WeekHot":
            retVal = aboutlinkvideo.GetVideoListByWeek(curPage, $("#hidUserID").val()).value;
            break;
        case "LinkDay":
            retVal = aboutlinkvideo.GetLinkVideoRankByDay("1", "Today", $("#hidUserID").val(), curPage).value;
            break;
        case "LinkWeek":
            retVal = aboutlinkvideo.GetLinkVideoRankByDay("1", "Week", $("#hidUserID").val(), curPage).value;
            break;
        case "ZTDay":
            retVal = aboutlinkvideo.GetLinkVideoRankByDay("2", "Today", $("#hidUserID").val(), curPage).value;
            break;
        case "ZTWeek":
            retVal = aboutlinkvideo.GetLinkVideoRankByDay("2", "Week", $("#hidUserID").val(), curPage).value;
            break;
        case "NewsVideo":
            retVal = aboutlinkvideo.GetNewsRank($("#hidUserID").val(), curPage).value;
            break;
        case "ChannelVideo":
            retVal = aboutlinkvideo.GetBestVideo($("#hidUserID").val(), 1, searchValue, curPage).value;
            break;
        case "ColumnVideo":
            retVal = aboutlinkvideo.GetBestVideo($("#hidUserID").val(), 2, searchValue, curPage).value;
            break;
        case "SearchByUserID":
            retVal = aboutlinkvideo.GetVideoByUserID($("#hidUserID").val(), searchValue, curPage).value;
            break;
        case "SearchByNickName":
            retVal = aboutlinkvideo.GetVideoByNickName($("#hidUserID").val(), searchValue, curPage).value;
            break;
    }
    var tempHtml = retVal;
    if (tempHtml != "") {
        $("#viewContent").html(tempHtml.split("$pager$")[0]);
        if (tempHtml.split("$pager$")[1] == undefined) {
            $(".pager").html("");
        } else {
            var pageHtml = tempHtml.split("$pager$")[1];
            $(".pager").html(pageHtml);
            if (curPage > 1) {
                document.documentElement.scrollTop = $("#subMenu").offset().top;   //兼容firefox
                document.body.scrollTop = $("#subMenu").offset().top;
                $("#viewContent").focus();
            }
        }
    }
    else {
        $("#viewContent").html("暂无信息");
        $(".pager").html("");
    }
}
function GetBestVideo(type, typeID) {
    if (type == 1) {
        $("#messageType").val("ChannelVideo");
    } else {
        $("#messageType").val("ColumnVideo");
    }
    $("#SearchValue").val(typeID);
    CreatePage(1);
}
function SearchVideoByUserID(userID) {
    $("#SearchValue").val(userID);
    $("#messageType").val("SearchByUserID");
    CreatePage(1);
}
function SearchVideoByKeyWord(curPage) {
    //$("#messageType").val("SearchByKeyWord");
    var keyWord = $("#searchInput_keywords").val();
    $.getJSON("http://192.168.1.98/search/interfaces/videoSeatch.aspx?jsoncallback=?", { keyword: keyWord, pagesize: 10, curpage: curPage }, function (json) {
        var allCount = parseInt(json.totalNum);
        var content = json.videoList;
        var html = "";
        if (allCount == 0) {
            html = "搜索不到你要的视频";
            $(".pager").html("");
        }
        if (content != undefined && content.length > 0) {
            for (var i = 0; i < content.length; i++) {
                html += aboutlinkvideo.GetHtmlByVideoId(curUserID, content[i].videoID).value;
            }
        }
        $("#viewContent").html(html);
        if (allCount > 10) {
            var pageHtml = aboutlinkvideo.GetPageHtmlForJs(allCount, curPage).value;
            $(".pager").html(pageHtml);
        }
    });
}
function seachVideoByNickName() {
    var SearchValue = $("#searchInput_user").val();
    $("#SearchValue").val(SearchValue);
    $("#messageType").val("SearchByNickName");
    CreatePage(1);
}
(function () {
    $('#searchInput_keywords').bind($.browser.opera ? "keypress" : "keydown", function (event) {
        if (event.keyCode == Ucenter.Event.keyBoard.RETURN) {
            event.preventDefault();
            var t = $(this);
            SearchVideoByKeyWord(1);
            return false;
        }
    }).focus(function () {

    }).blur(function () {
        var t = $(this);
        SearchVideoByKeyWord(1)
    });
    $('#searchInput_user').bind($.browser.opera ? "keypress" : "keydown", function (event) {
        if (event.keyCode == Ucenter.Event.keyBoard.RETURN) {
            event.preventDefault();
            var t = $(this);
            seachVideoByNickName();
            return false;
        }
    }).focus(function () {

    }).blur(function () {
        var t = $(this);
        seachVideoByNickName();
    });
})();